<?php

/**
 * Flickr Photosets - Configuration Page
 * Allows the user to set their configuration.
 * 
 * @author Brad Dougherty <bdougherty@gmail.com>
 * @version 2.0.2
 * @date 10/13/07
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License 3.0
 * @since File available since Release 1.0
 */

/*
Require the function library
This will include all other necessary files
*/
require_once 'lib.php';

/*
Initialize Flickr Photosets
*/
$fp = new FlickrPhotosetsConfig();

?>

<fb:title>Configuration</fb:title>

<?=$fp->print_dashboard('Configuration')?>

<?=$fp->print_messages()?>

<?php
/*
Show the option to Authenticate if no information is present in the database
*/
if (empty($fp->nsid)) { ?>

	<fb:editor action="<?=$fp->app_call_url?>/auth.php" labelwidth="0">

		<div style="padding:0 45px 0;margin-top:15px;">
			<h2 class="header">Flickr Account</h2>

			<p>Click on the Authenticate button below to setup your Flickr account. When you click Authenticate, you will be redirected to Flickr to authorize access.</p>

			<fb:editor-buttonset>
				<fb:editor-button name="auth" value="Authenticate"/>
			</fb:editor-buttonset>

		</div>

	</fb:editor>

<?php }
/*
Otherwise, show all of the configuration options
*/
else { ?>

	<div class="section">
		<a name="account" />
		<h2 class="header">Flickr Account</h2>
		<p style="font-size:12px;border:1px solid #e2c822;background-color:#fff9d7;padding:7px;"><strong>Your Facebook account is currently associated with <a href="<?=$fp->flickr->urls_getUserProfile($fp->nsid)?>"><?=$fp->flickr_user['username']?></a>.</strong></p>
		<p>Click on the Remove Account button below to remove your association with your Flickr account. Once you remove it, you can either add a different account, or the same one again.</p>
		
		<fb:editor action="" labelwidth="0">

			<fb:dialog id="remove_dialog" cancel_button=1>
				<fb:dialog-title>Remove Flickr Account</fb:dialog-title>
				<fb:dialog-content>
					<h3>Are you sure you want to remove your Flickr account from <?=$fp->app_name?>?</h3>
					<p>This <strong>will not</strong> remove the application from your Facebook account. You will be given the opportunity to revoke the permissions on Flickr once your account information is removed from <?=$fp->app_name?>.</p>
				</fb:dialog-content>
				<fb:dialog-button type="button" value="Remove" href="<?=$fp->app_url?>/auth.php?remove=1" />
			</fb:dialog>

			<fb:editor-buttonset>
				<input type="button" class="editorkit_button action" value="Remove Account" clicktoshowdialog="remove_dialog" />
			</fb:editor-buttonset>

		</fb:editor>
	</div>

	<div class="section">
		<a name="privacy" />
		<h2 class="header">Privacy Options</h2>
		<p><?=$fp->app_name?> respects your privacy. Using these settings you can change the privacy of your photos. By default, only your publicly visible photos on Flickr are displayed on Facebook. You can select to "loosen" your privacy settings by changing which kinds of photos are shown. <strong><em>Your profile box will be visible to anyone that can see your profile.</em></strong> You can limit who will see your profile box by going to the <a href="http://www.facebook.com/privacy.php?view=profile">Privacy Settings for your Profile</a> page.</p>
		
		<fb:editor action="">

			<fb:editor-custom label="Photo Privacy">
				Show photos marked as 
				<select name="privacy_filter">
					<option value="<?=$fp->privacy_filter['public']?>"<?php if ($fp->config['privacy_filter'] == $fp->privacy_filter['public']) { echo ' selected'; } ?>>Public</option>
					<option value="<?=$fp->privacy_filter['friends']?>"<?php if ($fp->config['privacy_filter'] == $fp->privacy_filter['friends']) { echo ' selected'; } ?>>Friends</option>
					<option value="<?=$fp->privacy_filter['family']?>"<?php if ($fp->config['privacy_filter'] == $fp->privacy_filter['family']) { echo ' selected'; } ?>>Family</option>
					<option value="<?=$fp->privacy_filter['friends_family']?>"<?php if ($fp->config['privacy_filter'] == $fp->privacy_filter['friends_family']) { echo ' selected'; } ?>>Friends &amp; Family</option>
					<option value="<?=$fp->privacy_filter['private']?>"<?php if ($fp->config['privacy_filter'] == $fp->privacy_filter['private']) { echo ' selected'; } ?>>Private</option>
				</select>
				<br/><span class="editor-actions"><small>Public photos will always be shown, in addition to the selected privacy setting.</small></span>
			</fb:editor-custom>

			<fb:editor-custom label="Facebook Visibility">
				Show photos to
				<select name="privacy_visibility">
					<option value="<?=$fp->privacy_visibility['all']?>"<?php if ($fp->config['privacy_visibility'] == $fp->privacy_visibility['all']) { echo ' selected'; } ?>>Everyone</option>
					<option value="<?=$fp->privacy_visibility['friends']?>"<?php if ($fp->config['privacy_visibility'] == $fp->privacy_visibility['friends']) { echo ' selected'; } ?>>My Friends Only</option>
					<option value="<?=$fp->privacy_visibility['non-limited']?>"<?php if ($fp->config['privacy_visibility'] == $fp->privacy_visibility['non-limited']) { echo ' selected'; } ?>>My Friends (non-limited)</option>
				</select>
				<br/><span class="editor-actions"><small>Non-limited excludes anyone on your limited profile list.</small></span>
			</fb:editor-custom>

			<fb:editor-custom label="My Name">
				<label for="privacy_name" class="normal">
					<input type="checkbox" style="width:auto;" id="privacy_name" name="privacy_name" value="1"<?php if ($fp->config['privacy_name'] == $fp->privacy_name['full']) { echo ' checked'; } ?> /> Show my full name
				</label>
			</fb:editor-custom>

			<fb:editor-buttonset>
				<fb:editor-button name="fp_privacy" value="Set"/>
				<fb:editor-button name="fp_privacy" value="Reset"/>
				<fb:editor-cancel href="<?=$fp->app_url?>/configure.php" />
			</fb:editor-buttonset>

		</fb:editor>
	</div>

	<div class="section">
		<a name="features" />
		<h2 class="header">Program Features</h2>
		<p>You can use these settings to enable and disable various parts of the application.</p>
		
		<fb:editor action="">

			<fb:editor-custom label="Enable">
				<label for="enable_profile" class="normal">
					<input type="checkbox" style="width:auto;margin-bottom:6px;" id="enable_profile" name="enable_profile" value="1" <?=($fp->config['enable_profile']) ? 'checked ' : '' ?>clicktotoggle="profile_options" clickthrough="true" /> Profile<br />
				</label>
				<label for="enable_newsfeed" class="normal">
					<input type="checkbox" style="width:auto;margin-bottom:6px;" id="enable_newsfeed" name="enable_newsfeed" value="1" <?=($fp->config['enable_newsfeed']) ? '' : '' ?> disabled /> News Feed Notifications<br />
				</label>
				<small>News feed notifications have been disabled until the bugs can be fixed.</small><br /><br/>
				<label for="enable_gallery" class="normal">
					<input type="checkbox" style="width:auto;margin-bottom:6px;" id="enable_gallery" name="enable_gallery" value="1" <?=($fp->config['enable_gallery']) ? 'checked ' : '' ?> clicktotoggle="gallery" clickthrough="true" /> Gallery
				</label>
				<div id="gallery" style="padding-left: 15px;<?=($fp->config['enable_gallery']) ? '' : 'display:none;'?>">
					<label for="enable_gallery_photostream" class="normal">
						<input type="checkbox" style="width:auto;margin-bottom:3px;" id="enable_gallery_photostream" name="enable_gallery_photostream" value="1" <?=($fp->config['enable_gallery_photostream']) ? 'checked ' : ''?>/> Photostream<br/>
					</label>
					<label for="enable_gallery_photosets" class="normal">
						<input type="checkbox" style="width:auto;margin-bottom:3px;" id="enable_gallery_photosets" name="enable_gallery_photosets" value="1" <?=($fp->config['enable_gallery_photosets']) ? 'checked ' : ''?>/> Photosets<br/>
					</label>
					<label for="enable_gallery_geotagged" class="normal">
						<input type="checkbox" style="width:auto;margin-bottom:6px;" id="enable_gallery_geotagged" name="enable_gallery_geotagged" value="1" <?=($fp->config['enable_gallery_geotagged']) ? 'checked ' : ''?>/> Geotagged
					</label>
				</div>
			</fb:editor-custom>

			<fb:editor-buttonset>
				<fb:editor-button name="fp_features" value="Set"/>
				<fb:editor-button name="fp_features" value="Reset"/>
				<fb:editor-cancel href="<?=$fp->app_url?>/configure.php" />
			</fb:editor-buttonset>

		</fb:editor>
	</div>

	<div class="section" id="profile_options" <?=($fp->config['enable_profile']) ? '' : 'style="display:none;"'?>>
		<a name="profile" />
		<h2 class="header">Profile Page Options</h2>
		<p>These settings change the appearance of the box on your profile page. Photos are displayed in rows of 2 if the box is in the narrow column, or 5 if it is in the wide column. Sets are displayed on their own row if in the narrow column, or in rows of 2 if in the wide column. You cannot show more than 30 photos or sets on your profile.</p>
		
		<script>
		function profilePageOptions(obj) {
			var selected = obj.getValue();
			
			// Sets
			if (selected == "<?=$fp->profile_display['sets']?>" || selected == "<?=$fp->profile_display['random_sets']?>") {
				// Hide these
				document.getElementById('profile_tags_field').setStyle('display', 'none');
				document.getElementById('profile_tagmode_field').setStyle('display', 'none');
				document.getElementById('profile_sortby_field').setStyle('display', 'none');
				
				// Show these
				document.getElementById('num_photos_field').setStyle('display', '');
				
				// Change the num_photos_field text
				changeNumPhotos('Sets');
			}
			// Overview
			else if (selected == "<?=$fp->profile_display['overview']?>") {
				// Hide these
				document.getElementById('num_photos_field').setStyle('display', 'none');
				document.getElementById('profile_tags_field').setStyle('display', 'none');
				document.getElementById('profile_tagmode_field').setStyle('display', 'none');
				document.getElementById('profile_sortby_field').setStyle('display', 'none');
			}
			// Photos
			else {
				// Show these
				document.getElementById('num_photos_field').setStyle('display', '');
				document.getElementById('profile_tags_field').setStyle('display', '');
				document.getElementById('profile_tagmode_field').setStyle('display', '');
				document.getElementById('profile_sortby_field').setStyle('display', '');
				
				// Change the num_photos_field text
				changeNumPhotos('Photos');
			}
			
		}
		
		function changeNumPhotos(string) {
			if (string == 'Sets') {
				document.getElementById("profile_display_label").setTextValue("Number of Sets:");
				document.getElementById("profile_display_small").setTextValue("Maximum 30 sets");
			}
			else {
				document.getElementById("profile_display_label").setTextValue("Number of Photos:");
				document.getElementById("profile_display_small").setTextValue("Maximum 30 photos");
			}
		}
		</script
		
		<form action="" method="post">
		<table class="editorkit" border="0" cellspacing="0" style="width:425px"><tr class="width_setter"><th style="width:75px"></th><td></td></tr>
			
			<tr><th class="detached_label"><label>Display:</label></th><td class="editorkit_row">
				<select name="profile_display" onchange="profilePageOptions(this);" onload="profilePageOptions(this);">
					<option value="<?=$fp->profile_display['last']?>"<?php if ($fp->config['profile_display'] == $fp->profile_display['last']) { echo ' selected'; } ?>>
						Most Recent Photos
					</option>
					<option value="<?=$fp->profile_display['recent']?>"<?php if ($fp->config['profile_display'] == $fp->profile_display['recent']) { echo ' selected'; } ?>>
						Fairly Recent Photos
					</option>
					<option value="<?=$fp->profile_display['random']?>"<?php if ($fp->config['profile_display'] == $fp->profile_display['random']) { echo ' selected'; } ?>>
						Random Photos
					</option>
					<option value="<?=$fp->profile_display['sets']?>"<?php if ($fp->config['profile_display'] == $fp->profile_display['sets']) { echo ' selected'; } ?>>
						Sets
					</option>
					<option value="<?=$fp->profile_display['random_sets']?>"<?php if ($fp->config['profile_display'] == $fp->profile_display['random_sets']) { echo ' selected'; } ?>>
						Random Sets
					</option>
					<option value="<?=$fp->profile_display['overview']?>"<?php if ($fp->config['profile_display'] == $fp->profile_display['overview']) { echo ' selected'; } ?>>
						Overview
					</option>
				</select>
			</td><td class="right_padding"></td></tr>
			
			<?php $photos_string = ($fp->config['profile_display'] == $fp->profile_display['sets']) ? 'Sets' : 'Photos' ; ?>
			<tr id="num_photos_field"<?=($fp->config['profile_display'] == $fp->profile_display['overview']) ? ' style="display:none;"' : '' ;?>><th class="detached_label"><label id="profile_display_label">Number of <?=$photos_string?>:</label></th><td class="editorkit_row">
				<input type="text" value="<?=$fp->config['profile_count']?>" name="profile_count" id="profile_count_photos" maxlength="2" class="numphotos" />
				<span class="editor-actions"><small id="profile_display_small">Maximum 30 <?=strtolower($photos_string)?></small></span>
			</td><td class="right_padding"></td></tr>
			
			<tr id="profile_tags_field"<?=($fp->config['profile_display'] == $fp->profile_display['overview'] or $fp->config['profile_display'] == $fp->profile_display['sets']) ? ' style="display:none;"' : '' ;?>><th class="detached_label"><label>Tags (optional):</label></th><td class="editorkit_row">
				<input type="text" value="<?=$fp->config['profile_tags']?>" name="profile_tags" class="" />
				<span class="editor-actions"><small>Optional comma-separated list of tags</small></span>
			</td><td class="right_padding"></td></tr>

			<tr id="profile_tagmode_field"<?=($fp->config['profile_display'] == $fp->profile_display['overview'] or $fp->config['profile_display'] == $fp->profile_display['sets']) ? ' style="display:none;"' : '' ;?>><th class="detached_label"><label>Tag Mode:</label></th><td class="editorkit_row">
				<select name="profile_tagmode">
					<option value="<?=$fp->profile_tagmode['any']?>"<?php if ($fp->config['profile_tagmode'] == $fp->profile_tagmode['any']) { echo ' selected'; } ?>>
						ANY tag
					</option>
					<option value="<?=$fp->profile_tagmode['all']?>"<?php if ($fp->config['profile_tagmode'] == $fp->profile_tagmode['all']) { echo ' selected'; } ?>>
						ALL tags
					</option>
				</select>
			</td><td class="right_padding"></td></tr>

			<tr id="profile_sortby_field"<?=($fp->config['profile_display'] == $fp->profile_display['overview'] or $fp->config['profile_display'] == $fp->profile_display['sets']) ? ' style="display:none;"' : '' ;?>><th class="detached_label"><label>Sort By:</label></th><td class="editorkit_row">
				<select name="profile_sort" id="profile_sort">
					<option value="<?=$fp->profile_sort['date_posted_desc']?>"<?php if ($fp->config['profile_sort'] == $fp->profile_sort['date_posted_desc']) { echo ' selected'; } ?>>
						Date Posted, Newest to Oldest
					</option>
					<option value="<?=$fp->profile_sort['date_posted_asc']?>"<?php if ($fp->config['profile_sort'] == $fp->profile_sort['date_posted_asc']) { echo ' selected'; } ?>>
						Date Posted, Oldest to Newest
					</option>
					<option value="<?=$fp->profile_sort['date_taken_desc']?>"<?php if ($fp->config['profile_sort'] == $fp->profile_sort['date_taken_desc']) { echo ' selected'; } ?>>
						Date Taken, Newest to Oldest
					</option>
					<option value="<?=$fp->profile_sort['date_taken_asc']?>"<?php if ($fp->config['profile_sort'] == $fp->profile_sort['date_taken_asc']) { echo ' selected'; } ?>>
						Date Taken, Oldest to Newest
					</option>
					<option value="<?=$fp->profile_sort['interesting_desc']?>"<?php if ($fp->config['profile_sort'] == $fp->profile_sort['interesting_desc']) { echo ' selected'; } ?>>
						Interestingness, Most to Least
					</option>
					<option value="<?=$fp->profile_sort['interesting_asc']?>"<?php if ($fp->config['profile_sort'] == $fp->profile_sort['interesting_asc']) { echo ' selected'; } ?>>
						Interestingness, Least to Most
					</option>
				</select>
			</td><td class="right_padding"></td></tr>

			<tr><th></th><td class="editorkit_buttonset">
				<input type="submit" class="editorkit_button action" value="Set" name="fp_profile" />
				<input type="submit" class="editorkit_button action" value="Reset" name="fp_profile" />
				<input type="submit" class="editorkit_button action" name="fp_profile" value="Preview" clickrewriteurl="<?=$fp->app_call_url?>/profile.php?handle=<?=$fp->uid?>&amp;preview" clickrewriteid="profilepreview" clicktoshow="profilepreview"/>
				<span class="cancel_link"><span>or</span><a href="<?=$fp->app_url?>/configure.php">Cancel</a></span>
			</td><td class="right_padding"></td></tr>

		</table></form>
		<div id="profilepreview" style="display:none;width:420px;margin:auto;"></div>
	</div>

	<div class="section">
		<a name="problems" />
		<h2 class="header">Problem Resolution</h2>
		<p>If the profile box has disappeared from your profile or you are having issues with the profile box not updating properly or giving errors:</p>
		
		<fb:editor action="">

			<fb:editor-buttonset>
				<fb:editor-button name="fp_problems" value="Reset Profile Box"/>
			</fb:editor-buttonset>

			<?php /* <div style="padding:0 30px 0;margin-top:15px;">
				<p>If the photos on your profile are out of date:</p>
			</div>

			<fb:editor-button name="refreshphotos" value="Refresh Photos"/> */ ?>

		</fb:editor>
	</div>

	<div class="section">
		<a name="donate" />
		<h2 class="header">Donate</h2>
		<p>If you find this application really useful, please consider donating.</p>
		
		<fb:editor action="https://www.paypal.com/cgi-bin/webscr">

			<fb:editor-buttonset>
				<fb:editor-button name="submit" value="Make a Donation" />
			</fb:editor-buttonset>
			<fb:editor-custom>
				<input type="hidden" name="cmd" value="_s-xclick">
				<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIHRwYJKoZIhvcNAQcEoIIHODCCBzQCAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwDQYJKoZIhvcNAQEBBQAEgYAzNweDNwpc+OhyjUYC2gw3pq8AzQys8cIyqad/itmbapyDU9CAF/pfVJ2YviNJV9Jw/ptuSkHt8ta6fhSvTox/S8RQm76Km0WO+hHPABrhCc5xWC6lGTTdGmc3yWsEdNWw3npHu5s9y//QOlC75JWHOPgUfIaUZYVsjX7/IIbwPTELMAkGBSsOAwIaBQAwgcQGCSqGSIb3DQEHATAUBggqhkiG9w0DBwQIPVN6TUJcTVWAgaDZPR1ZcvVV2ghrGrkNqktGk4rhVPiuRuTtPYUnpsHfsCt0q7/eaN4K6hg61Pj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